//
//  ShareViewController.m
//  wangzhe
//
//  Created by 李 佳伟 on 2017/11/27.
//  Copyright © 2017年 李 佳伟. All rights reserved.
//

#import "ShareViewController.h"
#import "JTCSM.h"
#import <ShareSDK/ShareSDK.h>
#import <ShareSDKUI/ShareSDK+SSUI.h>
#import "GetInfoClass.h"
@interface ShareViewController ()
{
    NSString *imagename;
    NSString *shareurl;
}
@end

@implementation ShareViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    self.navigationController.navigationBar.hidden = YES;
    [df isRemoveTarbar:YES];
    
    [[GetInfoClass shareSingle] getinfo];
    [GetInfoClass shareSingle].myblock = ^(UserInfoModel *Model) {
        imagename = Model.logo;
        shareurl = Model.share;
    };
    
    UIImageView *imageview = [[UIImageView alloc]initWithFrame:CGRectMake(0, -20,KCONTROLLERWith , KCONTROLLERHeight+20)];
    imageview.image = [UIImage imageNamed:@"shareimage.png"];
    [self.view addSubview:imageview];
    imageview.userInteractionEnabled = YES;
    
    UILabel*label = [UILabel initWithFrame:CGRectMake(0, 20, KSCREENWidth, 44) text:@"分享赢好礼" font:22 textAlignment:NSTextAlignmentCenter texcolor:[UIColor whiteColor] backgroundColor:[UIColor clearColor]];
    [self.view addSubview:label];
    
    UIButton *button = [[UIButton alloc] init];
    button.frame = CGRectMake(10, 20, 60, 44);
    [button setImage:[UIImage imageNamed:@"return_iv_white.png"] forState:UIControlStateNormal];
    [button setTitle:@"返回" forState:UIControlStateNormal];
    //        image的位置大小调整
    button.imageEdgeInsets = UIEdgeInsetsMake(12.5, 5, 12.5, 40);
    //        title的位置大小调整
    button.titleEdgeInsets = UIEdgeInsetsMake(0, -30, 0, 0);
    [button addTarget:self action:@selector(gotobackVC) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:button];
    
    UIView *backview = [[UIView alloc]initWithFrame:CGRectMake(0, KCONTROLLERHeight-200, KCONTROLLERHeight, 200)];
    backview.userInteractionEnabled = YES;
    [self.view addSubview:backview];
    [df addTapGestureRecognizerWithTarget:self action:@selector(sharedAtion) andaddView:backview];

    // Do any additional setup after loading the view.
}

- (void)sharedAtion{
    
    NSArray* imageArray = @[imagename];
//    （注意：图片必须要在Xcode左边目录里面，名称必须要传正确，如果要分享网络图片，可以这样传iamge参数 images:@[@"http://mob.com/Assets/images/logo.png?v=20150320"]）
    if (imageArray) {
        
        NSMutableDictionary *shareParams = [NSMutableDictionary dictionary];
        [shareParams SSDKSetupShareParamsByText:@"分享新用户注册链接，对方成功激活后，你的账户将获得20元感谢金。"
                                         images:imageArray
                                            url:[NSURL URLWithString:shareurl]
                                          title:@"王者管家"
                                           type:SSDKContentTypeAuto];
        //有的平台要客户端分享需要加此方法，例如微博
        [shareParams SSDKEnableUseClientShare];
        //2、分享（可以弹出我们的分享菜单和编辑界面）
        [ShareSDK showShareActionSheet:nil //要显示菜单的视图, iPad版中此参数作为弹出菜单的参照视图，只有传这个才可以弹出我们的分享菜单，可以传分享的按钮对象或者自己创建小的view 对象，iPhone可以传nil不会影响
                                 items:@[@(SSDKPlatformTypeSinaWeibo),
                                         @(SSDKPlatformSubTypeWechatSession),
                                         @(SSDKPlatformSubTypeWechatTimeline),
                                         @(SSDKPlatformTypeQQ)]
                           shareParams:shareParams
                   onShareStateChanged:^(SSDKResponseState state, SSDKPlatformType platformType, NSDictionary *userData, SSDKContentEntity *contentEntity, NSError *error, BOOL end) {
                       
                       switch (state) {
                           case SSDKResponseStateSuccess:
                           {
                               UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"分享成功"
                                                                                   message:nil
                                                                                  delegate:nil
                                                                         cancelButtonTitle:@"确定"
                                                                         otherButtonTitles:nil];
                               [alertView show];
                               break;
                           }
                           case SSDKResponseStateFail:
                           {
                               UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"分享失败"
                                                                               message:[NSString stringWithFormat:@"%@",error]
                                                                              delegate:nil
                                                                     cancelButtonTitle:@"OK"
                                                                     otherButtonTitles:nil, nil];
                               [alert show];
                               break;
                           }
                           default:
                               break;
                       }
                   }
         ];}
}

- (void)gotobackVC{
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
